﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Threading.Tasks;

namespace PhoneTestApp
{
    // The idea is that the source for these classes are generated statically, by sucking down
    // the XML from a device and parsing it to generate the class, types and methods
    // (For now I type them in manually)
    public class ContentDirectory : UPnP.Service
    {
        public ContentDirectory(string uri)
            : base(uri, "urn:schemas-upnp-org:service:ContentDirectory:1")
        {
        }

        //<action>
        //<name>Browse</name>
        //  <argumentList>
        //    <argument>
        //      <name>ObjectID</name>
        //      <direction>in</direction>
        //      <relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
        //    </argument>
        //    <argument>
        //      <name>BrowseFlag</name>
        //      <direction>in</direction>
        //      <relatedStateVariable>A_ARG_TYPE_BrowseFlag</relatedStateVariable>
        //    </argument>
        //    <argument>
        //      <name>Filter</name>
        //      <direction>in</direction>
        //      <relatedStateVariable>A_ARG_TYPE_Filter</relatedStateVariable>
        //    </argument>
        //    <argument>
        //      <name>StartingIndex</name>
        //      <direction>in</direction>
        //      <relatedStateVariable>A_ARG_TYPE_Index</relatedStateVariable>
        //    </argument>
        //    <argument>
        //      <name>RequestedCount</name>
        //      <direction>in</direction>
        //      <relatedStateVariable>A_ARG_TYPE_Count</relatedStateVariable>
        //    </argument>
        //    <argument>
        //      <name>SortCriteria</name>
        //      <direction>in</direction>
        //      <relatedStateVariable>A_ARG_TYPE_SortCriteria</relatedStateVariable>
        //    </argument>
        //    <argument>
        //      <name>Result</name>
        //      <direction>out</direction>
        //      <relatedStateVariable>A_ARG_TYPE_Result</relatedStateVariable>
        //    </argument>
        //    <argument>
        //      <name>NumberReturned</name>
        //      <direction>out</direction>
        //      <relatedStateVariable>A_ARG_TYPE_Count</relatedStateVariable>
        //    </argument>
        //    <argument>
        //      <name>TotalMatches</name>
        //      <direction>out</direction>
        //      <relatedStateVariable>A_ARG_TYPE_Count</relatedStateVariable>
        //    </argument>
        //    <argument>
        //      <name>UpdateID</name>
        //      <direction>out</direction>
        //      <relatedStateVariable>A_ARG_TYPE_UpdateID</relatedStateVariable>
        //    </argument>
        //  </argumentList>
        //</action>
        private static UPnP.Service.ActionInfo Browse_Info = new UPnP.Service.ActionInfo()
        {
            name = "Browse",
            argnames = new string[] { "ObjectID", "BrowseFlag", "Filter", "StartingIndex", "RequestedCount", "SortCriteria" },
            outargs = 4,
        };
        public class Browse_Result : UPnP.Service.ActionResult
        {
            public string Result;
            public uint NumberReturned;
            public uint TotalMatches;
            public uint UpdateID;

            public override void Fill(string[] rawdata)
            {
                Result = rawdata[0];
                NumberReturned = uint.Parse(rawdata[1]);
                TotalMatches = uint.Parse(rawdata[2]);
                UpdateID = uint.Parse(rawdata[3]);
            }
        }
        public async Task<Browse_Result> Browse(string ObjectID, string BrowseFlag, string Filter, uint StartingIndex, uint RequestedCount, string SortCriteria)
        {
            return await base.Action_Async(Browse_Info, new object[] { ObjectID, BrowseFlag, Filter, StartingIndex, RequestedCount, SortCriteria }, new Browse_Result()) as Browse_Result;
        }
    }
}
